package com.ruoyi.material_stock.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material_stock.domain.MaterialStock;
import com.ruoyi.material_stock.service.IMaterialStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资仓库Controller
 * 
 * @author ruoyi
 * @date 2025-08-22
 */
@RestController
@RequestMapping("/material_stock/material_stock")
public class MaterialStockController extends BaseController
{
    @Autowired
    private IMaterialStockService materialStockService;

    /**
     * 查询物资仓库列表
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialStock materialStock)
    {
        startPage();
        List<MaterialStock> list = materialStockService.selectMaterialStockList(materialStock);
        return getDataTable(list);
    }

    /**
     * 导出物资仓库列表
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:export')")
    @Log(title = "物资仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialStock materialStock)
    {
        List<MaterialStock> list = materialStockService.selectMaterialStockList(materialStock);
        ExcelUtil<MaterialStock> util = new ExcelUtil<MaterialStock>(MaterialStock.class);
        util.exportExcel(response, list, "物资仓库数据");
    }

    /**
     * 获取物资仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") Long stockId)
    {
        return success(materialStockService.selectMaterialStockByStockId(stockId));
    }

    /**
     * 新增物资仓库
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:add')")
    @Log(title = "物资仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialStock materialStock)
    {
        return toAjax(materialStockService.insertMaterialStock(materialStock));
    }

    /**
     * 修改物资仓库
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:edit')")
    @Log(title = "物资仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialStock materialStock)
    {
        return toAjax(materialStockService.updateMaterialStock(materialStock));
    }

    /**
     * 删除物资仓库
     */
    @PreAuthorize("@ss.hasPermi('material_stock:material_stock:remove')")
    @Log(title = "物资仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockIds}")
    public AjaxResult remove(@PathVariable Long[] stockIds)
    {
        return toAjax(materialStockService.deleteMaterialStockByStockIds(stockIds));
    }
}
